<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vuejs/vue.js"></script>
    <style>
        *{
            margin: 10px;
        }
        .demo1{
            height: 50px;
            background-color: aqua;
        }
        .box1{
            background-color: aqua;
            height: 80px;
        }
        .box2{
            background-color: green;
            height: 20px;
            
        }
        .list{
            width: 200px;
            height: 200px;
            background-color: gold;
            overflow: auto;
        }
        li{
            height: 100px;
            
        }
    </style>
</head>
<body>
    <div id="root">
        <h2>欢迎来到{{name}}</h2>
        <!-- <button v-on:click="showInfo">点我提升信息2</button>
        <button @click="showInfo2($event,66)">点我提升信息2</button> -->
        
        <!-- 阻止默认行为 同 event.preventDefault() -->
        <a href="http://www.baidu.com" @click.prevent="showInfo">点我提示信息</a>

        <!-- 阻止事件冒泡 同 event.stopPropagation() -->
        
        <div class="demo1" @click="showInfo">
            <button @click.stop="showInfo2">点我2</button>
            <!-- 修饰符可以连续写 -->
            <a href="http://www.baidu.com" @click.prevent.stop="showInfo">点我提示信息</a>
        </div>

        <!-- 事件只触发一次 -->
        <button @click.once="showInfo">点我一次</button>

        <!-- 使用事件的捕获模式 在事件捕获时处理事件 -->
        <div class="box1" @click.capture="showMsg(1)">
            div1
            <div class="box2" @click="showMsg(2)">
                div2
            </div>
        </div>
        <!-- self 只有event.target是当前操作的元素时才能触发事件 -->
        <div class="demo1" @click.self="showInfo">
            <button @click="showInfo">点我2</button>
        </div>

        <!-- passive 事件的默认行为立即执行 无需等待事件回调执行完毕 -->
        <ul @wheel.passive='demo' class="list">
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip=false;
        const vm=new Vue({
            el:"#root",
            data:{
                name:'新世界'
            },
            methods:{
                showInfo(event){
                    // console.log(event);
                    // console.log(event.target);
                    // console.log(this);//此处的this是vm
                    // alert('你好1')
                    console.log(event.target)
                },
                showInfo2(event,number){
                    // console.log(event);
                    // console.log(event.target);
                    // console.log(this,number);//此处的this是vm
                    alert('你好2')
                },
                showMsg(msg){
                    console.log(msg);
                },
                demo(){
                    for(let i=0;i<100000;i++){
                        console.log('###');
                    }
                    console.log('计算结束');
                }
            }
        })
    </script>
</body>
</html>